package com.zx.servlet;

import com.zx.dao.UserDao;
import com.zx.dao.impl.UserDaoImpl;
import com.zx.entity.User;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{

        String name= req.getParameter("username");
        String pwd= req.getParameter("password");
        UserDao userDao=new UserDaoImpl();
        User u= userDao.loginUser(new User(name,pwd));



        if (u!=null){
            res.sendRedirect("main.html");
        }else {
            res.sendRedirect("login.html");
        }


    }
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        super.doGet(req, res);
    }
}
